<?php


namespace app\user\controller;


use app\common\model\User;
use think\App;
use think\Controller;
use think\Db;
use think\facade\Session;

class LoggingBase extends Controller
{
    public $m_User;

    function __construct(App $app = null)
    {
        parent::__construct($app);

        $Token = Session::get('Token');
        if($Token == ''){
            header("Location: /index.php/user/");
            exit();
        }

        $User = new User();
        $UserData = $User->mb_Get("Token='$Token'");
        if ($UserData == null || $UserData->Level != Level_CRMUser || $UserData->IsDeleted != 0) {
            Session::delete('Token');
            header("Location: /index.php/user/");
            exit();
        }
        $this->m_User = $UserData;
    }

    protected function mb_Display($Title, $Menu, $Template = '', $Css = array(), $Js = array())
    {
        $SystemData = Db::table('system')->where('ID', 1)->find();
        if ($SystemData == null) $SystemName = '';
        else $SystemName = $SystemData['SystemName'];

        $this->assign('UserNick',$this->m_User->Nick);
        $this->assign('UserIcon',$this->m_User->Icon);

        $CompanyID = $this->m_User->CompanyID;
        $CompanyData = Db::table('company')->field('UserID')->where("IsDeleted='0' AND ID=$CompanyID")->find();
        if ($CompanyData != null && $CompanyData['UserID'] == $this->m_User->ID) {
            $this->assign('IsOwner', true);   //是主账户
        } else {
            $this->assign('IsOwner', false);   //不是是主账户
        }

        $this->assign('SystemName', $SystemName);
        $this->assign('Title', $Title);
        $this->assign('Menu', $Menu);
        $this->assign('Css', $Css);
        $this->assign('Js', $Js);
        $this->view->engine->layout('public/base');
        return $this->fetch($Template);
    }

}